package com.tsingteng.cosfun.ui.login.report;

import android.util.Log;

import com.tsingteng.cosfun.bean.BaseDataBean;
import com.tsingteng.cosfun.bean.CommBackBean;
import com.tsingteng.cosfun.bean.PersonBean;
import com.tsingteng.cosfun.bean.ReportBean;
import com.tsingteng.cosfun.callback.RxObserver;
import com.tsingteng.cosfun.mvp.presenter.BasePresenter;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

/**
 * 描述 :登录上报P层接口
 * 创建人: 常胜.
 * 时间:2018/8/18
 */
public class ReportPresenter extends BasePresenter<ReportContract.IReportView> implements ReportContract.IReportPresenter {

    private ReportContract.IReportView view;
    private  ReportModel model;
    public ReportPresenter(ReportContract.IReportView view){
        this.view = view;
        model = new ReportModel();
    }
    public ReportPresenter(){
        model = new ReportModel();
    }
    @Override
    public void loginReport() {
        view = getView();
        RxObserver<ReportBean> rxObserver = new RxObserver<ReportBean>(this) {
            @Override
            protected void onFaile(int errorCode, String errorMsg) {
//                Log.e("TAG666",errorMsg);
            }

            @Override
            protected void onSuccess(ReportBean status) {
                view.showReportData(status);
            }
        };
        model.getReportModel(rxObserver);
        addDisposable(rxObserver);
    }

    @Override
    public void getNotReadCount() {
        view = getView();
        RxObserver<ReportBean> rxObserver = new RxObserver<ReportBean>(this) {
            @Override
            protected void onFaile(int errorCode, String errorMsg) {

            }

            @Override
            protected void onSuccess(ReportBean reportBean) {
              view.showReadCount(reportBean);
            }
        };
        model.gotNotReadCount(rxObserver);
        addDisposable(rxObserver);
    }

    @Override
    public void getReadAll() {
        Callback<BaseDataBean<ReportBean>> callback = new Callback<BaseDataBean<ReportBean>>() {
            @Override
            public void onResponse(Call<BaseDataBean<ReportBean>> call, Response<BaseDataBean<ReportBean>> response) {
                view.showReadAll();
            }

            @Override
            public void onFailure(Call<BaseDataBean<ReportBean>> call, Throwable t) {
            }
        };
        model.getReadAllMsg(callback);
    }

    @Override
    public void getFollowCount(long time) {
        RxObserver<CommBackBean> rxObserver = new RxObserver<CommBackBean>(this) {
            @Override
            protected void onFaile(int errorCode, String errorMsg) {
                view.showFail(errorMsg);
            }

            @Override
            protected void onSuccess(CommBackBean commBackBean) {
                view.showFollowCount(commBackBean);
            }
        };
        model.getFollowCount( System.currentTimeMillis(), time,rxObserver);
        addDisposable(rxObserver);
    }
}
